package dowm1;

public class BankCard {
    // 余额属性
    private double balance;

    public BankCard(double balance) {
        this.balance = balance;
    }
    // 存钱方法
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("存入金额: " + amount + " 元，当前余额: " + balance + " 元");
        } else {
            System.out.println("存入金额必须大于0");
        }
    }

    // 取钱方法
    public boolean withdraw(double amount) {
        if (amount > 0 && amount <= balance) {
            balance -= amount;
            System.out.println("取出金额: " + amount + " 元，当前余额: " + balance + " 元");
            return true;
        } else {
            System.out.println("余额不足或取款金额不合法");
            return false;
        }
    }

    // 获取余额
    public double getBalance() {
        return balance;
    }
}
